/* ****************************************************************************
 *
 * Copyright (c) Microsoft Corporation. 
 *
 * This source code is subject to terms and conditions of the Microsoft Public License. A 
 * copy of the license can be found in the License.html file at the root of this distribution. If 
 * you cannot locate the  Microsoft Public License, please send an email to 
 * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound 
 * by the terms of the Microsoft Public License.
 *
 * You must not remove this notice, or any other, from this software.
 *
 * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
 * KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
 * PARTICULAR PURPOSE.
 * ***************************************************************************/

// STLMatrix.h: interface for the TSTLMatrix class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_STLMATRIX_H__26579C88_04DE_4DD6_BB0C_E9703BE4FCF6__INCLUDED_)
#define AFX_STLMATRIX_H__26579C88_04DE_4DD6_BB0C_E9703BE4FCF6__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "StlAlgo.h"

namespace std
{

/*! \brief A minimal matrix class

  \ingroup ContourLibGroup
*/
template < class T, class A = allocator<T> >
class TSTLMatrix : public vector<T,A>
{
public:
	TSTLMatrix(const A& al = A())
		: vector<T,A>(al) {};
	TSTLMatrix(typename A::size_type m, typename A::size_type n, const T& x = T(), const A& al = A())
		: vector<T,A>(m*n,x,al)	{ m_iM=m; m_iN=n;};
	TSTLMatrix(const TSTLMatrix& m)
		: vector<T,A>(m)		{ ASSERT(m.size()==m.m_iM*m.m_iN); m_iM=m.m_iM; m_iN=m.m_iN; };
	TSTLMatrix<T>& operator = (const TSTLMatrix& m)
	{	if (this != & m) { this->vector<T,A>::operator =(m); ASSERT(m.size()==m.m_iM*m.m_iN); m_iM=m.m_iM; m_iN=m.m_iN;}  return *this;};
	virtual ~TSTLMatrix(){};

	T& operator() (typename A::size_type i, typename A::size_type j)			
	{	
		ASSERT(size()==m_iM*m_iN); 
		ASSERT(i<m_iM); 
		ASSERT(j<m_iN); 
		return at(i*m_iN+j);
	};
	T operator() (typename A::size_type i, typename A::size_type j)const		
	{ 
		ASSERT(size()==m_iM*m_iN); 
		ASSERT(i<m_iM); 
		ASSERT(j<m_iN); 
		return at(i*m_iN+j);
	};

	size_t nrows() const { return m_iM;};
	size_t ncols() const { return m_iN;};
	void clear() { m_iM=m_iN=0; vector<T,A>::clear();};
	virtual void resize(typename A::size_type m, typename A::size_type n, const T& x = T()) { m_iM=m; m_iN=n; vector<T,A>::resize(m_iM*m_iN,x);};
	bool NormRows();

private:
	typename A::size_type m_iM;
	typename A::size_type m_iN;
};

}

#endif // !defined(AFX_STLMATRIX_H__26579C88_04DE_4DD6_BB0C_E9703BE4FCF6__INCLUDED_)
